package com.blt.car.home.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.blt.car.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by xgp on 2017/6/29.
 */

public class CityAdapter extends BaseAdapter {

    LayoutInflater inflater;
    List<String> cityList;

    public CityAdapter(Context context) {
        inflater = LayoutInflater.from(context);
        cityList=new ArrayList<>();
    }

    public void add(List<String> data) {
        cityList.addAll(data);
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return cityList.size();
    }

    @Override
    public Object getItem(int position) {
        return cityList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View v, ViewGroup parent) {
        if (v == null) {
            v = inflater.inflate(R.layout.item_city_chose, parent, false);
        }
        TextView cityName = (TextView) v.findViewById(R.id.item_city_name);
        cityName.setText(cityList.get(position));
        return v;
    }
}
